package com.kiseny.dao;

import java.util.List;

import org.hibernate.FetchMode;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.kiseny.po.Link;
import com.kiseny.po.MappingAccountLink;

public class MappingAccountLinkDAO extends BaseDAO<MappingAccountLink> {
    
    @SuppressWarnings("unchecked")
    public List<Link> getLinkListByAccountId (int id) {
        List<Link> linkList = null;
        
        DetachedCriteria criteria = DetachedCriteria.forClass(MappingAccountLink.class);
        criteria.setFetchMode("account", FetchMode.JOIN);
        criteria.setFetchMode("link", FetchMode.JOIN);
        
        criteria.add(Restrictions.eq("deleteFlag", new Boolean(false)));
        
        criteria.add(Restrictions.eq("account.id", id));

        try {
            linkList = (List<Link>) getHibernateTemplate().findByCriteria(criteria);

        } catch (RuntimeException e) {
            getLogger().error("Fail to execute it.", e);
            throw e;
        }
        
        return linkList;
    }

}
